using Avalonia;
using Avalonia.Data.Converters;
using System;
using System.Globalization;

namespace AvaloniaUiKit.Converters
{
    /// <summary>
    /// 布尔值转可见性的转换器
    /// </summary>
    public class BoolToVisibilityConverter : IValueConverter
    {
        /// <summary>
        /// True对应的可见性
        /// </summary>
        public bool TrueAsVisible { get; set; } = true;
        
        /// <summary>
        /// 转换方法
        /// </summary>
        public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                var result = boolValue;
                if (!TrueAsVisible)
                {
                    result = !result;
                }
                
                return result ? AvaloniaProperty.UnsetValue : AvaloniaProperty.UnsetValue;
            }
            
            return AvaloniaProperty.UnsetValue;
        }
        
        /// <summary>
        /// 反向转换方法
        /// </summary>
        public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            return AvaloniaProperty.UnsetValue;
        }
    }
} 